using System.Text;

namespace Base7
{
    public class Solution
    {
        public string ConvertToBase7(int num)
        {
            bool isNegative = false;
            if (num < 0)
            {
                num = -num;
                isNegative = true;
            }
            
            StringBuilder sb = new StringBuilder();
            while (num >= 7)
            {
                sb.Insert(0, num % 7);
                num /= 7;
            }

            sb.Insert(0, num);
            if (isNegative)
            {
                sb.Insert(0, '-');
            }

            return sb.ToString();
        }
    }
}